﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using util;
using dto;
using MySql.Data;
using MySql.Data.MySqlClient;
using common;
using System.Collections;
using System.Data;
namespace dao
{
    // process ForgetPassword, Feedback
    public class PopupManagerDAO
    {
        /* Author : Jenny
         * Date : 16/4/2012
         * function sendFeeback
         * parameter subject, contents
         * send a feedback to manager
         * return Boolean
         */ 
        public Boolean sendFeedback(String subject, String contents)
        {
            Boolean result = false;
            try
            {
                DataUtil.connect();
                String cmdText = "sp_SendFeedback";
                MySqlParameter[] arrParam = new MySqlParameter[5];
                arrParam[0] = new MySqlParameter("_UserID", Constant.USER_LOGIN.Id);
                arrParam[1] = new MySqlParameter("_Subject", subject);
                arrParam[2] = new MySqlParameter("_Contents", contents);
                arrParam[3] = new MySqlParameter("_IDLog", Constant.LOG_ID);
                arrParam[4] = new MySqlParameter("_Actions", Constant.DR_ACTIONS_VARIABLE["varFeedback"]);
                result = DataUtil.executeNonQuery(cmdText, arrParam);
            }
            catch (Exception ex)
            {
            }
            return result;
        }
        /* Author : Jenny
         * Date : 16/4/2012
         * function getAllPopupByConditionOfForgetPasswordOrFeedback
         * parameter subject, username, actions(is feedback or forget password)
         * get all feedback or forget password by conditions
         * return DataTable
         */
        public DataTable getAllPopupByConditionOfForgetPasswordOrFeedback(String status, String username, String actions)
        {
            DataTable dt = new DataTable();
            try
            {
                DataUtil.connect();
                String cmdText = "sp_getAllPopupByConditionOfForgetPasswordOrFeedback";
                MySqlParameter[] arrParam = new MySqlParameter[3];
                arrParam[0] = new MySqlParameter("_Status", status);
                arrParam[1] = new MySqlParameter("_Username", username);
                arrParam[2] = new MySqlParameter("_Actions", actions);
                dt = DataUtil.executeStore(cmdText, arrParam);
            }
            catch (Exception ex)
            {

            }
            return dt;
        }
        /* Author : Jenny
         * Date : 16/4/2012
         * function getCountUnreadMessagesOfFeedBackAndForgetPassword
         * parameter actions(is system lock user)
         * get count of unread feedback and forget password
         * return int
         */
        public int getCountUnreadMessagesOfFeedBackAndForgetPassword(String actions)
        {
            int count = -1;
            try
            {
                DataUtil.connect();
                String cmdText = "sp_getCountUnreadMessagesOfFeedBackAndForgetPassword";
                MySqlParameter[] arrParam = new MySqlParameter[1];
                arrParam[0] = new MySqlParameter("_Actions", actions);
                MySqlDataReader reader = DataUtil.executeReader(cmdText, arrParam);
                if (reader.Read())
                    count = Convert.ToInt32(reader["CountUnread"].ToString());
            }
            catch (Exception ex)
            {

            }
            return count;
        }
        /* Author : Jenny
        * Date : 16/4/2012
        * function getCountUserLockByLoginFail
        * parameter actions(is system lock user)
        * get count of new user lock by system because login fail 3 times
        * return int
        */
        public DataTable sp_getNewSystemLockUserByLoginFail(String actions)
        {
            DataTable dt = new DataTable();
            try
            {
                DataUtil.connect();
                String cmdText = "sp_getNewSystemLockUserByLoginFail";
                MySqlParameter[] arrParam = new MySqlParameter[1];
                arrParam[0] = new MySqlParameter("_Actions", actions);
                dt = DataUtil.executeStore(cmdText, arrParam);
                
            }
            catch (Exception ex)
            {

            }
            return dt;
        }
        public Boolean viewFeedbackContents(String id)
        {
            Boolean result = false;
            try
            {
                DataUtil.connect();
                String cmdText = "sp_ViewFeedbackContents";
                MySqlParameter[] arrParam = new MySqlParameter[1];
                arrParam[0] = new MySqlParameter("_ID", id);
                result = DataUtil.executeNonQuery(cmdText, arrParam);
            }
            catch (Exception ex)
            {
            }
            return result;
        }
    }
}
